package com.j4dream.property.javabasic.char_byte_encoding;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;

public class CharToByte {
    public static void main(String[] args) {
        char eng = 'c';
        char chi = '中';

        CharBuffer cb = CharBuffer.allocate(1);

        cb.put(chi);

        cb.flip();

        ByteBuffer bb = Charset.forName("utf-8").encode(cb);

        byte [] b = bb.array();

        System.out.println(b);

        byte[] by = "中E".getBytes();
        for (int i = 0; i < by.length; i++) {
            System.out.println(by[i]);
        }

        String s = new String(by);

        System.out.println(s);

    }
}